<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<base th:href="@{/}"><!-- 不用base就使用th:src="@{/js/jquery.min.js} -->
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-登录</title>
	<link rel="stylesheet" type="text/css" href="/css/reset.css">
	<link rel="stylesheet" type="text/css" href="/css/main.css">
	<script type="text/javascript" src="/js/jquery-1.12.4.min.js"></script>
</head>
<body>
	<div class="login_top clearfix">
		<a href="../../page/index.html" class="login_logo"><img src="/images/logo02.png"></a>
	</div>

	<div class="login_form_bg" style="height: 500px">
		<div class="login_form_wrap clearfix">
			<div class="login_banner fl"></div>
			<div class="slogan fl">日夜兼程 · 急速送达</div>
			<div class="login_form fr" style="height: 420px">
				<div class="login_title clearfix">
					<h1>用户登录</h1>
					<a href="/toRegister">立即注册</a>
				</div>
				<div style="padding-left: 20px;margin-top: 30px;width: 255px">
					<div style="height: 38px;width: 250px;margin-bottom: 30px">
						邮箱：<input style="height: 22px;width: 200px"  name="email" id="email" placeholder="请输入你的邮箱">
						<span id="emailSpan" style="margin-left: 100px;padding-left: 50px;">&nbsp;&nbsp;&nbsp;</span>
					</div>
					<div style="height: 38px;width: 250px;margin-bottom: 30px">
						密码：<input style="height: 22px;width: 200px" type="password" name="password" id="password" placeholder="请输入你的密码">
						<span id="passwordSpan" style="margin-left: 50px">&nbsp;&nbsp;&nbsp;</span>
					</div>
					<div style="height: 38px;width: 260px;margin-bottom: 30px">
						验证码：<input style="height: 22px;width: 200px" name="code" id="code" placeholder="请输入你的验证码">
						<span id="codeSpan" style="margin-left: 50px">&nbsp;&nbsp;&nbsp;</span>
					</div>

					<div style="height: 34px;width: 250px;margin-left: 20px">
						<img id="mycode" src="/user/getLoginCode" height="34px" width="160px" />
						<a onclick="refresh()" style="color: black;cursor: pointer">换一张</a>
					</div>
					<button id="login" style="width: 100px;height: 38px;margin-left: 10px;margin-top: 26px;margin-right: 20px">登录</button>
					<button id="forgetPwd" style="width: 100px;height: 38px;margin-top: 10px;margin-right: 10px">忘记密码</button>

				</div>
			</div>
		</div>
	</div>

	<div class="footer no-mp">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 专门吃饭有限公司 All Rights Reserved</p>
		<p>电话：88888888   京ICP备*******8号</p>
	</div>
</body>
	<script>
		// 验证该邮箱是否存在
		$("#email").blur(function (){
			var email = $("#email").val();
			var url = "/user/checkLoginEmail";
			var param = {"email":email};
			$.post(url,param,function (data){
				if (data.code == 200){
					$("#emailSpan").html(data.message);
					$("#emailSpan").attr("style","color:green");
				}else {
					$("#emailSpan").html(data.message);
					$("#emailSpan").attr("style","color:red");
				}
			},"json");
		});

		// 点击发送连接再次发送验证码
		function refresh(){
			$("#mycode").attr("src","/user/getLoginCode?time="+new Date().getTime())
		}

		// 点击登录
		$("#login").click(function (data){
			var email = $("#email").val();
			var password = $("#password").val();
			var code = $("#code").val();
			var param = {"email":email,"password":password,"code":code};
			var url = "/user/doLogin";
			$.post(url,param,function (data){
				if (data.code == 200 || data.code == 222){
					// 登录成功去首页
					alert("登录成功");
					// 不同身份跳去不同页面
					if (data.code ==200){
						location.href = "/index";
					}else {
						location.href = "/toSellerCenterInfo";
					}
				}else{
					alert(data.message);
				}
			},"json");
		});

		// 点击忘记密码：重置密码
		$("#forgetPwd").click(function (){
				location.href="/toResetPwd";
		});

	</script>
</html>